package com.hexinfo.dmpro.data.transfer.common.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.data.transfer.common.model.AgentInfo;
import com.hexinfo.dmpro.data.transfer.common.service.IAgentInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@AllArgsConstructor
@RequestMapping("/api/agent")
@Api(value = "agent", tags = "AGENT管理")
public class AgentInfoController {

    @Autowired
    private IAgentInfoService agentInfoService;

    @ApiOperation(value = "AGENT注册", notes = "AGENT注册")
    @PostMapping(value = "/register")
    @AnonymousAccess
    public ResponseEntity<Object> agentRegister(@RequestBody AgentInfo agentInfo) {
        agentInfoService.register(agentInfo);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "AGENT心跳", notes = "AGENT心跳")
    @PostMapping(value = "/heartbeat")
    @AnonymousAccess
    public ResponseEntity<Object> agentHeartbeat(@RequestBody AgentInfo agentInfo) {
        agentInfoService.agentHeartbeat(agentInfo);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation(value = "AgentSession集合", notes = "AgentSession集合")
    @GetMapping(value = "/agentSessionList")
    @AnonymousAccess
    public ResponseEntity<Object> agentSessionList() {
        return ResponseEntity.ok(agentInfoService.querySessionList());
    }
}
